package com.mini.cn.goods.requestinfo;

import com.alibaba.fastjson.JSONObject;
import com.mini.cn.goods.common.frame.BaseHttpNetWork;
import com.mini.cn.goods.common.frame.RequestInfo;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: fly
 * Date: 2023/1/8
 * Time: 13:20
 */
public class WeixinGroupOrderRequest extends BaseHttpNetWork {

    public WeixinGroupOrderRequest(RequestInfo info) {
        super(info);
        method="POST";
    }

    @Override
    public void setHeader() {

    }

    @Override
    public byte[] setBody(RequestInfo info) {
        WeixinGroupOrderRequestInfo weixinGroupOrderRequestInfo = (WeixinGroupOrderRequestInfo) info;
        try {
            JSONObject object = new JSONObject();
            object.put("touser", weixinGroupOrderRequestInfo.openid);
            object.put("template_id", weixinGroupOrderRequestInfo.template_id);
            object.put("url","");
            JSONObject array=new JSONObject();
            //frist
            JSONObject fristremark=new JSONObject();
            fristremark.put("value", weixinGroupOrderRequestInfo.frist);
            //"color":"#173177"
            fristremark.put("color", "#173177");
            array.put("first",fristremark);
            //keynote1 orderId
            JSONObject orderIdObject=new JSONObject();
            orderIdObject.put("value", weixinGroupOrderRequestInfo.orderId);
            array.put("keyword1",orderIdObject);
            //keynote2 pickCode
            JSONObject pickCodeObject=new JSONObject();
            pickCodeObject.put("value",weixinGroupOrderRequestInfo.pickCode);
            array.put("keyword2",pickCodeObject);
            //keynote3 time
            JSONObject timeObject=new JSONObject();
            timeObject.put("value",new Date());
            array.put("keyword3",timeObject);
            //keynote4 address
            JSONObject addObject=new JSONObject();
            addObject.put("value",weixinGroupOrderRequestInfo.address);
            array.put("keyword4",addObject);
            //keynote5 remark
            JSONObject remarkObject=new JSONObject();
            remarkObject.put("value", weixinGroupOrderRequestInfo.remark);
            array.put("remark",remarkObject);
            object.put("data", array);
            String requestString=object.toString();
            System.out.println("发送模版包体 =="+requestString);
            return requestString.getBytes("utf-8");
        } catch (Exception e) {
            // TODO: handle exception
            return null;
        }
    }

    @Override
    public void modifyUrl(RequestInfo info) {

    }
}
